<html>
<head><meta charset="utf-8"><title>Termination/Exit Status Stabilization · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html">Termination/Exit Status Stabilization</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227660898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/227660898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#227660898">(Feb 24 2021 at 19:53)</a>:</h4>
<p>Hi, the <a class="stream" data-stream-id="257204" href="/#narrow/stream/257204-project-error-handling">#project-error-handling</a> is currently polishing the rough edges of the <code>Termination</code> trait and also looking at ways <code>ExitCode</code>s can interact with it. For now, we are waiting for <a href="https://github.com/rust-lang/rfcs/pull/2895">Generic Member Access</a> to implement reporting <code>Error</code>s at the termination (apart from the <code>ExitCode</code>). The question is, how to approach this implementation from the official way? There is an <a href="https://github.com/rust-lang/rust/issues/43301">RFC</a> for tracking the <code>Termination</code> trait stabilization - so we could just add the implementation to the GMA PR.</p>



<a name="227661104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/227661104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#227661104">(Feb 24 2021 at 19:55)</a>:</h4>
<p>For now the idea around <code>ExitCode</code>s is to return an arbitrary numeric value (which can be then used by the user to interpret it).</p>



<a name="227674196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/227674196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#227674196">(Feb 24 2021 at 21:16)</a>:</h4>
<p>Yay!  Exciting that <code>ExitCode</code> is finally getting some love.</p>



<a name="227677506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/227677506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#227677506">(Feb 24 2021 at 21:38)</a>:</h4>
<p>:D</p>



<a name="228123702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/228123702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#228123702">(Feb 28 2021 at 11:10)</a>:</h4>
<p><span class="user-mention" data-user-id="204346">@Ashley Mannix</span> could you help us come up with  a proper way of including our improvements and stabilizing it?</p>



<a name="230044828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230044828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230044828">(Mar 12 2021 at 15:13)</a>:</h4>
<p>I am currently working on tying the <code>Termination</code> with printing 'ExitCode's on program exit. I read various documents like <a href="https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426/15">pre-RFC</a> or <a href="https://github.com/rust-lang/project-error-handling/issues/7">this issue</a>. <br>
I like the existing pre-RFC simplicity, but I am afraid it is not enough and it may require much maintenance to sustain the proper error codes if some changes occur in the operating systems (especially other than the holy trio Windows/Unix/MacOs). I am curious about your ideas on this topic? Generally <a href="https://github.com/rust-lang/project-error-handling/issues/22#issuecomment-738270096">this comment</a> is a good proposition of how may this look. There seemed to be more interest on the topic in the past, but now it seems to be stagnant <span aria-label="frown" class="emoji emoji-1f641" role="img" title="frown">:frown:</span></p>



<a name="230067208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230067208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230067208">(Mar 12 2021 at 17:25)</a>:</h4>
<p>I don't think we should be printing the exit code, just using it as the process exit code.</p>



<a name="230073771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230073771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230073771">(Mar 12 2021 at 18:09)</a>:</h4>
<p>Right, so just returning and no printing. The errors should be printed upon exiting the process though, am I right?</p>



<a name="230074229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230074229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230074229">(Mar 12 2021 at 18:13)</a>:</h4>
<p>that's a decision made by the process running the program</p>



<a name="230074272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230074272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230074272">(Mar 12 2021 at 18:13)</a>:</h4>
<p>if it's bash, it'll by default print if the process exited due to a signal, but a bare exit status is also available</p>



<a name="230079232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230079232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230079232">(Mar 12 2021 at 18:50)</a>:</h4>
<p><span class="user-mention" data-user-id="344196">@Jakub Duchniewicz</span> Do you mean the Error part of a Result?</p>



<a name="230079241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230079241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230079241">(Mar 12 2021 at 18:50)</a>:</h4>
<p>That should be printed, as it currently is.</p>



<a name="230079323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230079323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230079323">(Mar 12 2021 at 18:51)</a>:</h4>
<p>Yes</p>



<a name="230079550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230079550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230079550">(Mar 12 2021 at 18:52)</a>:</h4>
<p>It's purely ExitCode that shouldn't be printed; that should only be returned.</p>



<a name="230079665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230079665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230079665">(Mar 12 2021 at 18:53)</a>:</h4>
<p>This part is quite unambiguous, but I would like to gather some opinions on having more <code>ExitCode</code>s and having them mapped to OS codes</p>



<a name="230082121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230082121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230082121">(Mar 12 2021 at 19:10)</a>:</h4>
<p>If <code>ExitCode</code> is going to be useful for this purpose, I don't think we should attempt to set any semantics other than "0 is success, non-zero is failure, provide any non-zero value you like".</p>



<a name="230082173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230082173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230082173">(Mar 12 2021 at 19:10)</a>:</h4>
<p>People may need to implement an arbitrary exit-code convention.</p>



<a name="230122119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230122119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230122119">(Mar 13 2021 at 00:56)</a>:</h4>
<p>Things like constants for the <code>sysexits.h</code> ones seem plausible, but I agree that people will need arbitrary ones.</p>
<p>Even just being able to <code>return ExitCode(2)</code> from <code>main</code> instead of needing to call <code>exit</code> (and bypass drops) would be nice.</p>



<a name="230122198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230122198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230122198">(Mar 13 2021 at 00:58)</a>:</h4>
<p>I think we should separate the os mappings issue from the rest of <code>Termination</code> stabilization</p>



<a name="230122226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230122226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230122226">(Mar 13 2021 at 00:59)</a>:</h4>
<p>like everyone else said, just being able to provide a specific exit code for a graceful exit is probably enough for most people's use cases, and until someone makes a proposal for mappings and constants they should be able to make a 3rd party crate that provides those same mappings</p>



<a name="230122400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230122400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230122400">(Mar 13 2021 at 01:01)</a>:</h4>
<p>my expectation is that we will just want to add a constructor for <code>ExitStatus</code> from arbitrary integers, and then we can leave the specialization with exit code extraction as part of the generic member access rfc for errors</p>



<a name="230187118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230187118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230187118">(Mar 13 2021 at 20:33)</a>:</h4>
<p>IIRC one of the questions for it last time was what type(s) it should use.  Since <code>exit</code> takes <code>int</code>, but <code>WEXITSTATUS</code> only gives the bottom 8 bits of that, but <a href="https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getexitcodeprocess">Windows preserves a whole <code>DWORD</code> (<code>u32</code>)</a>.</p>



<a name="230187649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230187649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230187649">(Mar 13 2021 at 20:43)</a>:</h4>
<p>Yes, this is one of the issues with choosing a proper implementation</p>



<a name="230527285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230527285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230527285">(Mar 16 2021 at 15:00)</a>:</h4>
<p>So the small draft of changes in scope is <a href="https://gist.github.com/JDuchniewicz/c326357c0d0a0b0e4c89b44dd1e28d19">here</a>. The remaining question is what should be the underlying value of <code>ExitCode</code> since Termination returns <code>i32</code> which is later translated to <code>isize</code> in <code>start</code> function</p>



<a name="230527582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230527582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230527582">(Mar 16 2021 at 15:01)</a>:</h4>
<p>Probably <span class="user-mention" data-user-id="125270">@scottmcm</span> would know more about this topic and why it is <code>not isize</code> in the first place</p>



<a name="230527698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230527698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230527698">(Mar 16 2021 at 15:02)</a>:</h4>
<p>Is there a reason it's translated to isize?</p>



<a name="230527869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230527869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230527869">(Mar 16 2021 at 15:02)</a>:</h4>
<p>Exit codes are typically <code>int</code>s which generally equates to <code>i32</code>.</p>



<a name="230528006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230528006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230528006">(Mar 16 2021 at 15:03)</a>:</h4>
<p>(Which, yes, are used in different ways depending on the platform)</p>



<a name="230528586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230528586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230528586">(Mar 16 2021 at 15:06)</a>:</h4>
<p>that why it is even more interesting why they were set to <code>u8</code> in the first place</p>



<a name="230528674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230528674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230528674">(Mar 16 2021 at 15:07)</a>:</h4>
<p>probably because unices use only 255  of exit codes?</p>



<a name="230528697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230528697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230528697">(Mar 16 2021 at 15:07)</a>:</h4>
<p>but I doubt it</p>



<a name="230538323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230538323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230538323">(Mar 16 2021 at 15:58)</a>:</h4>
<p>That seems like a likely explanation, honestly.</p>



<a name="230538416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230538416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230538416">(Mar 16 2021 at 15:59)</a>:</h4>
<p>Might also be that that's all we can portably count on.</p>



<a name="230553742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230553742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230553742">(Mar 16 2021 at 17:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="344196">Jakub Duchniewicz</span> <a href="#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization/near/230527582">said</a>:</p>
<blockquote>
<p>Probably <span class="user-mention silent" data-user-id="125270">scottmcm</span> would know more about this topic and why it is <code>not isize</code> in the first place</p>
</blockquote>
<p><a href="#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization/near/230187118">https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization/near/230187118</a></p>
<p>Originally posix was 0..=255, but now it's <code>c_int</code>, and on windows it's <code>DWORD</code> (<code>u32</code>), so it's not obvious what the correct type is.  (And then there's esoteric platforms where it's a string, or something.)</p>
<p>But in general, the answer for <code>ExitCode</code> is that there wasn't really substantial design -- it was just tossing something together to get non-<code>()</code>-<code>main</code> stabilized.  Probably it's <code>i32</code> because there was an <a href="https://github.com/rust-lang/rust/pull/48497/files#diff-d28320a72819402338af92259522275ed5e735179368ca421704fbdd937cea07L1456"><code>impl Termination for i32</code></a> and <code>ExitCode</code> was created to punt on the question of whether <code>i32</code> was the right type, or whether <em>any</em> integer type as a return from <code>main</code> was desirable.</p>



<a name="230555702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230555702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230555702">(Mar 16 2021 at 17:24)</a>:</h4>
<p>so I guess we are ok with changing the underlying type of <code>ExitCode</code> to be <code>i32</code>?</p>



<a name="230556130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230556130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230556130">(Mar 16 2021 at 17:26)</a>:</h4>
<p>Do you mean of <code>start</code>?  The struct is <code>pub struct ExitCode(imp::ExitCode);</code>, which seems plausible, as it allows different types for different platforms...</p>



<a name="230558964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230558964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230558964">(Mar 16 2021 at 17:43)</a>:</h4>
<p>Linux  <code>sys_exit</code> and <code>sys_exit_group</code> both mask <code>error_code&amp;0xff</code> in the kernel</p>



<a name="230559193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230559193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230559193">(Mar 16 2021 at 17:44)</a>:</h4>
<p>Worth noting, I <em>think</em> Fuchsia might actually use <code>u64</code> here?</p>



<a name="230559204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230559204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230559204">(Mar 16 2021 at 17:44)</a>:</h4>
<p>That was mentioned on an unrelated PR.</p>



<a name="230559233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230559233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230559233">(Mar 16 2021 at 17:45)</a>:</h4>
<p>So <code>i32</code> doesn't seem like a portable assumption.</p>



<a name="230560684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230560684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230560684">(Mar 16 2021 at 17:52)</a>:</h4>
<p>Maybe <code>ExitCode: From&lt;u8&gt;</code> everywhere, with platform-specific constructors from other things?  (And just never expose the underlying field as <code>pub</code>.)</p>



<a name="230563102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230563102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230563102">(Mar 16 2021 at 18:05)</a>:</h4>
<p>That sounds like the right answer, yeah.</p>



<a name="230563210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230563210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230563210">(Mar 16 2021 at 18:06)</a>:</h4>
<p>Least-common-denominator portable API that'll cover most common cases, platform-specific API to use the full extent of the platform.</p>



<a name="230563623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230563623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230563623">(Mar 16 2021 at 18:08)</a>:</h4>
<p>Yeah, I feel like the 90% (or more) case is just codes in 0-10.</p>



<a name="230563692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230563692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230563692">(Mar 16 2021 at 18:09)</a>:</h4>
<p>i think i even saw a 13 recently <span aria-label="eyes" class="emoji emoji-1f440" role="img" title="eyes">:eyes:</span></p>



<a name="230564755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230564755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230564755">(Mar 16 2021 at 18:15)</a>:</h4>
<p>13 is for SIGPIPE, signal(7) lists up to 31: <a href="https://man7.org/linux/man-pages/man7/signal.7.html">https://man7.org/linux/man-pages/man7/signal.7.html</a></p>



<a name="230565053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230565053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230565053">(Mar 16 2021 at 18:17)</a>:</h4>
<p>signals are returned differently than just exit codes (although some shells might not display/handle them differently (?))</p>



<a name="230565200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230565200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230565200">(Mar 16 2021 at 18:18)</a>:</h4>
<p>I just ran <code>sleep 1000</code> and then used <code>kill -13</code> on it, and the bash <code>$?</code>is 141 (i.e. 128+sig)</p>



<a name="230565259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230565259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230565259">(Mar 16 2021 at 18:19)</a>:</h4>
<p>but I don't remember if that's just a shell-ism</p>



<a name="230565306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230565306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230565306">(Mar 16 2021 at 18:19)</a>:</h4>
<p><code>WTERMSIG</code> uses separate bits than a normal exit code</p>



<a name="230565599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230565599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230565599">(Mar 16 2021 at 18:21)</a>:</h4>
<p>yeah that's just the shell. zsh does the same +128 thing for signals, but the kernel encodes it separately.</p>



<a name="230571544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230571544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230571544">(Mar 16 2021 at 19:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization/near/230563623">said</a>:</p>
<blockquote>
<p>Yeah, I feel like the 90% (or more) case is just codes in 0-10.</p>
</blockquote>
<p>There's also common usage of codes around 128 and codes around 255, for programs that want to pass through some other program's exit code but carve out a bit of space for their own errors.</p>



<a name="230571618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230571618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230571618">(Mar 16 2021 at 19:01)</a>:</h4>
<p>But yeah, I think most portable programs will be happy using a <code>u8</code>, and only specific programs on non-UNIX platforms will need to return specific errors above 255.</p>



<a name="230573867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Termination/Exit%20Status%20Stabilization/near/230573867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakub Duchniewicz <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization.html#230573867">(Mar 16 2021 at 19:16)</a>:</h4>
<p>In the <a href="https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426/15">pre-RFC</a> the difference between signals and codes is explained quite well. But AFAIK we will not be doing this distinction and just return whatever is in the <code>ExitCode</code> (assuming the user put something there).</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>